package sites.manager.admin.site;

import ch.qos.logback.core.net.SyslogOutputStream;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import org.springframework.web.servlet.ModelAndView;
import sites.manager.common.kit.Ret;
import sites.manager.common.kit.SiteInfo;
import sites.manager.common.model.Site;

import javax.validation.constraints.NotBlank;

/**
 * 站点管理
 */
@Controller
@RequestMapping("/site")
public class SiteController {
	
	@Autowired
	private SiteService srv;

	/**
	 * 进入站点管理界面
	 *
	 * @return
	 */
	@RequestMapping("/enterSiteMng")
	public String enterSiteMng() {
		return "site/pageSiteMng";
	}

	/**
	 * 进入站点新增界面
	 *
	 * @return
	 */
	@RequestMapping("/enterSiteAdd")
	public String enterSiteAdd(){
		return "site/respSiteAdd";
	}

	/**
	 * 获取站点数据
	 *
	 * @return
	 */
	@RequestMapping("/getSites")
	@ResponseBody
	public Ret getSites(Site site, int page, int limit) {
		return srv.getSites(site, page, limit);
	}

	/**
	 * 保存站点
	 *
	 * @return
	 */
	@RequestMapping("/saveSite")
	@ResponseBody
	public Ret saveSite(@Validated Site site) {
		return srv.saveSite(site);
	}

	/**
	 * 删除站点信息
	 *
	 * @param ids
	 * @return
	 */
	@RequestMapping("/deleteSite/{ids}")
	@ResponseBody
	public Ret deleteSite(@NotBlank @PathVariable String ids){
		return srv.deleteSite(ids);
	}

	@RequestMapping("/enterSiteEdit/{id}")
	public String enterSiteEdit(@NotBlank @PathVariable String id, Model model){
		Site site = srv.getSiteById(id);
		model.addAttribute("site", site);
		return "site/respSiteEdit";
	}

	@RequestMapping("/updateSite")
	@ResponseBody
	public Ret updateSite(@Validated Site site){
		return srv.updateSite(site);
	}

	@RequestMapping("/resetSite/{id}")
	@ResponseBody
	public Ret resetSite(@NotBlank @PathVariable String id){
		return srv.resetSite(id);
	}
}
